# -*-coding:utf-8-*-
import os

from common import localdisk

__author__ = 'Jason'

#
def format1(dir):
    files = []
    fielnum =0

    list = os.listdir(dir)#列出目录下的所有文件和目录
    for line in list:
        filepath = os.path.join(dir,line) # .decode('gbk', 'ignore').encode('utf-8')
        print(filepath)
        if os.path.isdir(filepath):#如果filepath是目录，则再列出该目录下的所有文件
            # build(filepath)
            """for li in os.listdir(filepath):
                files.append(filepath)
                fielnum = fielnum + 1"""
            print("暂不实现")
        elif os.path:#如果filepath是文件，直接列出文件名
            extName = os.path.splitext(line)[1].lower()
            pureName = os.path.splitext(line)[0]
            if extName == ".pdf":
                print(pureName.join(extName))
                blocks = pureName.split(" ")
                if len(blocks) == 2:
                    newName = blocks[1] + " " + blocks[0].strip()
                    localdisk.renameFile(filepath,newName)
            print(filepath)
            fielnum = fielnum + 1

    print('文件数: '+ str(fielnum))
    return  files